package tr.edu.yildiz.dap.appeditor.componentproviders.basic;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import tr.edu.yildiz.dap.appeditor.componentproviders.MavenComponentProvider;
import tr.edu.yildiz.dap.appeditor.componentproviders.WorkspaceComponentProvider;
import tr.edu.yildiz.dap.appeditor.model.AppComponent;

public class ComponentManager {

	public static final String WORKSPACE = "WORKSPACE";
	public static final String MAVEN = "MAVEN";
	
	static Map<String,IComponentProvider> componentProviderMap;
	
	static ComponentManager instance;
	
	public static ComponentManager getInstance() {
		if (instance == null)
			instance = new ComponentManager();
		return instance;
	}
	
	public void init() {
		componentProviderMap = new HashMap<String,IComponentProvider>();
		componentProviderMap.put(WORKSPACE,new WorkspaceComponentProvider(this));
		componentProviderMap.put(MAVEN,new MavenComponentProvider(this));
	}
	
	public List<AppComponent> getComponentList(){
		if (componentProviderMap == null)
			init();
		List<AppComponent> list = new ArrayList<AppComponent>();
		Iterator iterator = componentProviderMap.entrySet().iterator();
		while (iterator.hasNext()) {
			IComponentProvider componentProvider = ((Entry<String,IComponentProvider>) iterator.next()).getValue();
			list.addAll(componentProvider.listComponents());
		}
		return list;
	}
	
	public IComponentProvider getMavenComponentProvider(){
		return componentProviderMap.get(MAVEN);
	}
	
	public IComponentProvider getWorkspaceComponentProvider(){
		return componentProviderMap.get(WORKSPACE);
	}
	
}
